/*
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
Sample Output
Case 1:
14 1 4

Case 2:
7 1 6
 */
package com.yuan.algorithms.training201608;

import java.util.Scanner;

/**
 * @author YouYuan
 * @contact 1265161633@qq.com
 * @date 2016年8月16日 上午9:49:24
 * @descript 
 */
public class A_MaxSubSequence {

	static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		while(in.hasNext()) {
			int n = in.nextInt();
			int No = 0;
			for (int i = 0; i < n; i++) {
				No++;
				int len = in.nextInt();
				int start = 1;
				int end = 1;
				int max = Integer.MIN_VALUE;
				int tempStart = 1;
				int sum = 0;
				for (int j = 1; j <= len; j++) {
					int num = in.nextInt();
					sum += num;
					if (sum > max) {
						max = sum;
						start = tempStart;
						end = j;
					}
					if (sum < 0) {
						tempStart = j + 1;
						sum = 0;
					}
				}
				if (No != 1) {
					System.out.println();
				}
				System.out.println("Case " + No + ":");
				System.out.println(max + " " + start + " " + end);
			}
		}
	}
}
